home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / examples / object / obj_tess.pro < prev    next >
Text File  |  1997-07-08  |  3KB  |  89 lines

  1. ;-------------------------------------------------------------
  2. ; This procedure file defines the procedure obj_tess, which is
  3. ; used as an example in Chapter 7 of _Objects and Object Graphics_.
  4. ;
  5. ; The example uses the tessellator object to convert a concave
  6. ; polygon into a number of convex polygons (triangles). A "hole"
  7. ; is also placed into the polygon using tessellation.
  8. ;-------------------------------------------------------------
  9.  
  10. PRO obj_tess
  11.         
  12. ; Create an object hierarchy.
  13. oWin = OBJ_NEW('IDLgrWindow')
  14. oView = OBJ_NEW('IDLgrView',VIEWPLANE_RECT=[-0.1,-0.1,1.2,1.2])
  15. oModel = OBJ_NEW('IDLgrModel')
  16.  
  17. ; Define vertices of a concave polygon.
  18. fPoly1 = [[0,1],[0,0],[1,0],[1,.3],[.5,.3],[.5,.7],[1,.7],[1,1]]
  19.  
  20. ; Define vertices of a second polygon, to add as a "hole".
  21. fPoly2 = [[.2,.2],[.4,.2],[.4,.4],[.2,.4]]
  22.  
  23. ; Create a filled polygon object and an outline polygon object.
  24. ; Both polygons objects will (eventually) contain multiple polygons
  25. ; and will display the same vertex data in two different ways.
  26. oPoly = OBJ_NEW('IDLgrPolygon',STYLE=2,COLOR=[0,255,0])
  27. oLine = OBJ_NEW('IDLgrPolygon',STYLE=1,COLOR=[0,0,255])
  28.  
  29. ; Create the object hierarchy
  30. oView->Add,oModel
  31. oModel->Add,oPoly
  32. oModel->Add,oLine
  33.  
  34. ; Draw the existing concave polygon twice: once filled and once
  35. ; in outline. Note that the filled polygon is drawn incorrectly.
  36.  
  37. oPoly->SetProperty,DATA=fPoly1
  38. oLine->SetProperty,DATA=fPoly1
  39.  
  40. oWin -> Draw, oView
  41.  
  42. ; Prompt for user input before proceeding.
  43. var=''
  44. READ, var, PROMPT='Press Return to tesselate and re-draw polygons.'
  45.  
  46.  
  47. ; Create a tessellator object.
  48. oTess = OBJ_NEW('IDLgrTessellator')
  49.  
  50. ; Convert a concave polygon to a series of triangles. The two
  51. ; polygon objects are changed to use the new convex polygon
  52. ; data.
  53. oTess->AddPolygon,fPoly1
  54. iStatus = oTess->tessellate(fVerts,iConn)
  55. IF (iStatus eq 1) THEN BEGIN
  56.    oPoly->SetProperty,DATA=fVerts,POLYGONS=iConn
  57.    oLine->SetProperty,DATA=fVerts,POLYGONS=iConn
  58.    oWin->Draw,oView
  59. ENDIF ELSE BEGIN
  60.    PRINT,'Unable to tessellate.'
  61.    oWin->Erase
  62. ENDELSE
  63.  
  64. ; Prompt for user input before proceeding.
  65. READ, var, PROMPT='Press Return to add a hole to the polygon'
  66.  
  67. ; Add a hole to the polygon
  68. oTess->Reset
  69. oTess->AddPolygon,fPoly1
  70. oTess->AddPolygon,fPoly2,/INTERIOR
  71. iStatus = oTess->tessellate(fVerts,iConn)
  72. IF (iStatus eq 1) THEN BEGIN
  73.    oPoly->SetProperty,DATA=fVerts,POLYGONS=iConn
  74.    oLine->SetProperty,DATA=fVerts,POLYGONS=iConn
  75.    oWin->Draw,oView
  76. ENDIF ELSE BEGIN
  77.    PRINT,'Unable to tessellate.'
  78.    oWin->Erase
  79. ENDELSE
  80.  
  81. ; Prompt for user input before proceeding.
  82. READ, var, PROMPT='Press Return to destroy the objects.'
  83.  
  84. OBJ_DESTROY,oTess
  85. OBJ_DESTROY,oWin
  86. OBJ_DESTROY,oView
  87.  
  88. END
  89.